#!/bin/sh
set -e

case "$1" in
configure)
    if ! /usr/bin/getent group docker >/dev/null; then
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo ""
        echo " WARNING: docker is not installed!"
        echo ""
        echo " If you need run baetyl in docker container mode, please install docker first:"
        echo ""
        echo " 'curl -sSL https://get.docker.com | sh'"
        echo " 'systemctl enable docker'"
        echo " 'systemctl restart docker'"
        echo ""
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo ""
        echo ""
    fi
    if [ ! -x /bin/systemctl -a ! -x /usr/bin/systemctl ]; then
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo ""
        echo " WARNING: systemd is not installed!"
        echo ""
        echo " Baetyl should be supervised by daemon tools, such as systemd or supervisor."
        echo " Otherwise it will exit and can't restart during the master OTA. If you only "
        echo " want to run baetyl in the foregroud, use the following command: "
        echo ""
        echo " 'baetyl start'"
        echo ""
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo ""
        echo ""
    fi
    echo "==============================================================================="
    echo ""
    echo "                              Baetyl"
    echo "  Baetyl is started and supervised by systemd. Use the following commands "
    echo "  to start, restart or stop baetyl:"
    echo ""
    echo "    'sudo systemctl start baetyl'"
    echo "    'sudo systemctl restart baetyl'"
    echo "    'sudo systemctl stop baetyl'"
    echo ""
    echo "  About design or configurations of Baetyl, please visit "
    echo ""
    echo "  https://docs.baetyl.io/en/latest/overview/Design.html for help."
    echo ""
    echo "  Baetyl is running in docker container mode by default. And Baetyl "
    echo "  also supports native process mode. "
    echo ""
    echo "  If you need run baetyl in native mode, please visit"
    echo "  https://docs.baetyl.io/en/latest/install/Install-from-source.html for help."
    echo ""
    echo "==============================================================================="
    ;;

abort-upgrade | abort-remove | abort-deconfigure) ;;

\
    *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
    ;;
esac

#DEBHELPER#

exit 0
